<?php
include_once("seguranca.php"); // Inclui o arquivo com o sistema de seguran�a
protegePagina();

if (file_exists("inicializa.php")) {
    require "inicializa.php";
} else {
    echo "Arquivo inicializa.php nao foi encontrado";
    exit;
}

if (!function_exists("Abre_Conexao")) {
    echo "Erro o arquivo inicializa.php foi alterado, nao existe a fun��o Abre_Conexao";
    exit;
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
-->
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Ant&ocirc;nio Martiniano P&aacute;dua</title>
        <meta content="text/html; charset=utf-8" http-equiv="content-type" />
        <script type="text/javascript" src="js/CkEditor/ckeditor.js"></script>
        <script src="js/CkEditor/sample.js" type="text/javascript"></script>
        <script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
        <link href="js/CkEditor/sample.css" rel="stylesheet" type="text/css" />
        <link rel="stylesheet" type="text/css" href="css/styleeditar.css" />
        <link rel="stylesheet" type="text/css" href="css/stylenovo.css" />


        <script>
            function confirmarexcluir(id,pagina){	 
                if (!confirm("Deseja apagar esta foto?")){ 
                    return false;
                }else{
                    //alert("Id: " + id + " Pagina: "+pagina);					
                    window.location = "Excluir.php?id=" + id+"&pagina="+pagina;						
                }       
            }
            function confirmarexcluirVideo(id,pagina){	 
                if (!confirm("Deseja apagar este video?")){ 
                    return false;
                }else{
                    //alert("Id: " + id + " Pagina: "+pagina);
                    window.location = "Excluirvideo.php?id=" + id+"&pagina="+pagina;						
                }       
            }  
        </script>



        <script>
        
            function validarcampos(form){
            
            
                if(form.descricao.value==""){
                    alert("Preencha o campo descrição.");
                    return false;
                
                }
            
            
                if (form.linkvideo.value=="") {
                    alert("Preencha o link do video corretamente.");
                    return false;
                }
                
                              
            
                form.submit();
            }
        
        
        function validacampofoto(form){
            
            
                if(form.descricao.value==""){
                    alert("Preencha o campo descrição.");
                    return false;
                
                }
            
               if(form.arquivo1.value==""){
                    alert("Escolha uma foto.");
                    return false;
                
                }
                          
                form.submit();
            }
        

        </script>

    </head>
    <body>

        <?php
        if (protegeEdicao()) {
            echo "<div id=\"fundologin\">\n<div class=\"meiologin\"> <h3>Ol&aacute;, " . $_SESSION['usuarioNome'] . "</h3><a href=\"Logout.php\">Sair</a>  </div></div>";
        }
        ?>
        <h1 class="samples">
            <?php
            $pagina = $_GET['pg'];
            echo "<center>Editar Pagina " . $pagina . "</center>";
            ?>
        </h1>



        <!-- This <div> holds alert messages to be display in the sample page. -->
        <div id="alerts">
            <noscript>
                <p>
                    <strong>CKEditor Requer JavaScript para Rodar</strong>. Por Favor Ative o Javascript.
                </p>
            </noscript>
        </div>



        <div id="texto">


            <div class="categoria">


                <form action="Salvar.php" method="post">
                    <p>
                        <?php
                        $re = mysql_query("SELECT * FROM  conteudo WHERE pagina = '" . $pagina . "'");
                        $l = mysql_fetch_array($re);
                        $texto = $l["Texto"];
                        echo "<textarea cols=\"80\" id=\"editor1\" name=\"editor1\" rows=\"10\">" . $texto . "</textarea>";
                        ?>			 

                        <script type="text/javascript">
                            //<![CDATA[

                            CKEDITOR.replace( 'editor1',
                            {
                                /*
                                 * Style sheet for the contents
                                 */
						
                                skin : 'office2003',
                                contentsCss : 'body {color:#000; background-color#:FFF;}',
                                extraPlugins : 'autogrow',
                                autoGrow_minHeight : 600,
                                /*
                                 * Simple HTML5 doctype
                                 */
                                docType : '<!DOCTYPE HTML>',

                                /*
                                 * Core styles.
                                 */
                                coreStyles_bold	: { element : 'b' },
                                coreStyles_italic	: { element : 'i' },
                                coreStyles_underline	: { element : 'u'},
                                coreStyles_strike	: { element : 'strike' },

                                /*
                                 * Font face
                                 */
                                // Define the way font elements will be applied to the document. The "font"
                                // element will be used.
                                font_style :
                                    {
                                    element		: 'font',
                                    attributes		: { 'face' : '#(family)' }
                                },

                                /*
                                 * Font sizes.
                                 */
                                fontSize_sizes : 'xx-small/1;x-small/2;small/3;medium/4;large/5;x-large/6;xx-large/7',
                                fontSize_style :
                                    {
                                    element		: 'font',
                                    attributes	: { 'size' : '#(size)' }
                                } ,

                                /*
                                 * Font colors.
                                 */
                                colorButton_enableMore : true,

                                colorButton_foreStyle :
                                    {
                                    element : 'font',
                                    attributes : { 'color' : '#(color)' }
                                },

                                colorButton_backStyle :
                                    {
                                    element : 'font',
                                    styles	: { 'background-color' : '#(color)' }
                                },

                                /*
                                 * Styles combo.
                                 */
                                stylesSet :
                                    [
                                    { name : 'Computer Code', element : 'code' },
                                    { name : 'Keyboard Phrase', element : 'kbd' },
                                    { name : 'Sample Text', element : 'samp' },
                                    { name : 'Variable', element : 'var' },

                                    { name : 'Deleted Text', element : 'del' },
                                    { name : 'Inserted Text', element : 'ins' },

                                    { name : 'Cited Work', element : 'cite' },
                                    { name : 'Inline Quotation', element : 'q' }
                                ],

                                on : { 'instanceReady' : configureHtmlOutput }
                            });

                            /*
                             * Adjust the behavior of the dataProcessor to avoid styles
                             * and make it look like FCKeditor HTML output.
                             */
                            function configureHtmlOutput( ev )
                            {
                                var editor = ev.editor,
                                dataProcessor = editor.dataProcessor,
                                htmlFilter = dataProcessor && dataProcessor.htmlFilter;

                                // Out self closing tags the HTML4 way, like <br>.
                                dataProcessor.writer.selfClosingEnd = '>';

                                // Make output formatting behave similar to FCKeditor
                                var dtd = CKEDITOR.dtd;
                                for ( var e in CKEDITOR.tools.extend( {}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent ) )
                                {
                                    dataProcessor.writer.setRules( e,
                                    {
                                        indent : true,
                                        breakBeforeOpen : true,
                                        breakAfterOpen : false,
                                        breakBeforeClose : !dtd[ e ][ '#' ],
                                        breakAfterClose : true
                                    });
                                }
					
						


                                // Output properties as attributes, not styles.
                                htmlFilter.addRules(
                                {
                                    elements :
                                        {
                                        $ : function( element )
                                        {
                                            // Output dimensions of images as width and height
                                            if ( element.name == 'img' )
                                            {
                                                var style = element.attributes.style;

                                                if ( style )
                                                {
                                                    // Get the width from the style.
                                                    var match = /(?:^|\s)width\s*:\s*(\d+)px/i.exec( style ),
                                                    width = match && match[1];

                                                    // Get the height from the style.
                                                    match = /(?:^|\s)height\s*:\s*(\d+)px/i.exec( style );
                                                    var height = match && match[1];

                                                    if ( width )
                                                    {
                                                        element.attributes.style = element.attributes.style.replace( /(?:^|\s)width\s*:\s*(\d+)px;?/i , '' );
                                                        element.attributes.width = width;
                                                    }

                                                    if ( height )
                                                    {
                                                        element.attributes.style = element.attributes.style.replace( /(?:^|\s)height\s*:\s*(\d+)px;?/i , '' );
                                                        element.attributes.height = height;
                                                    }
                                                }
                                            }

                                            // Output alignment of paragraphs using align
                                            if ( element.name == 'p' )
                                            {
                                                style = element.attributes.style;

                                                if ( style )
                                                {
                                                    // Get the align from the style.
                                                    match = /(?:^|\s)text-align\s*:\s*(\w*);/i.exec( style );
                                                    var align = match && match[1];

                                                    if ( align )
                                                    {
                                                        element.attributes.style = element.attributes.style.replace( /(?:^|\s)text-align\s*:\s*(\w*);?/i , '' );
                                                        element.attributes.align = align;
                                                    }
                                                }
                                            }

                                            if ( !element.attributes.style )
                                                delete element.attributes.style;

                                            return element;
                                        }
                                    },

                                    attributes :
                                        {
                                        style : function( value, element )
                                        {
                                            // Return #RGB for background and border colors
                                            return convertRGBToHex( value );
                                        }
                                    }
                                } );
                            }


                            function InsertHTML()
                            {
                                // Get the editor instance that we want to interact with.
                                var oEditor = CKEDITOR.instances.editor1;
                                var value = document.getElementById( 'htmlArea' ).value;

                                // Check the active editing mode.
                                if ( oEditor.mode == 'wysiwyg' )
                                {
                                    // Insert HTML code.
                                    // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#insertHtml
                                    oEditor.insertHtml( value );
                                }
                                else
                                    alert( 'You must be in WYSIWYG mode!' );
                            }

                            function GetContents()
                            {
                                // Get the editor instance that you want to interact with.
                                var oEditor = CKEDITOR.instances.editor1;

                                // Get editor contents
                                // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#getData
                                document.getElementById( 'htmlArea' ).value = oEditor.getData();
                            }
			

                            /**
                             * Convert a CSS rgb(R, G, B) color back to #RRGGBB format.
                             * @param Css style string (can include more than one color
                             * @return Converted css style.
                             */
                            function convertRGBToHex( cssStyle )
                            {
                                return cssStyle.replace( /(?:rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\))/gi, function( match, red, green, blue )
                                {
                                    red = parseInt( red, 10 ).toString( 16 );
                                    green = parseInt( green, 10 ).toString( 16 );
                                    blue = parseInt( blue, 10 ).toString( 16 );
                                    var color = [red, green, blue] ;

                                    // Add padding zeros if the hex value is less than 0x10.
                                    for ( var i = 0 ; i < color.length ; i++ )
                                        color[i] = String( '0' + color[i] ).slice( -2 ) ;

                                    return '#' + color.join( '' ) ;
                                });
                            }
                            //]]>
                        </script>
                    </p>
                    <?php
                    echo "<input type=\"hidden\" name=\"pagina\" value=\"" . $pagina . "\" />";
                    ?>
                    <input type="submit" value="Salvar" class="botao" />		
                </form>
            </div>

            <hr></hr>

            <div class="categoria">
                <?php
                echo "<form method=\"post\" name=\"formfoto\" action=\"recebe_upload.php?pg=" . $pagina . "\" enctype=\"multipart/form-data\">"
                ?>

                <fieldset class="fields">


                    <legend><span class="spa">Inserir foto:</span></legend>

                    <table cellpadding="10" border="0" width="100%" >
                        <tr>

                            <td>
                                <label>Descricao:</label>
                                <input name="descricao" type="text" id="descricao" maxlength="94" class="legenda" />	
                            </td>
                        </tr>

                        <tr>
                            <td>
                                <input id="arquivo1" name="arquivo1" class="fakeupload" type="text" />
                                <input type="file" name="arquivo" class="realupload" onchange="this.form.arquivo1.value = this.value;"/>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input type="button" value="Enviar" class="botao" onclick="validacampofoto(formfoto)" />
                            </td>
                        </tr>
                    </table>
                </fieldset>    

                <?php
                echo "</form>"
                ?>

                <br></br>




                <table width="100%" class="tab" >

                    <tr>		
                        <td><label>UrlFoto</label></td>
                        <td><label>Descricao</label></td>
                        <td><label>Acoes</label></td>
                    </tr>




                    <?php
                    $re = mysql_query("SELECT fotosgaleria.fotosgaleriaId, fotosgaleria.UrlFoto, fotosgaleria.Descricao
									FROM conteudo, conteudofotosgaleria, fotosgaleria
									WHERE conteudo.pagina =  '" . $pagina . "' AND 
									conteudofotosgaleria.FotosgaleriaId = fotosgaleria.FotosgaleriaId AND
									conteudofotosgaleria.ConteudoId = conteudo.ConteudoId");

                    if ($l = mysql_fetch_array($re)) {
                        do {
                            $url = $l["UrlFoto"];
                            $descricao = $l["Descricao"];
                            $id = $l["fotosgaleriaId"];
                            echo "<tr>						
							<td>&nbsp;<img src=\"Fotos/" . $url . "\"  height=\"100\" width=\"100\" /></td>		
							<td>&nbsp;<label>$descricao</label></td>
                            <td><input type=\"button\" class=\"botao\" value=\"Excluir\" onclick=confirmarexcluir($id,'$pagina');></td>						
						</tr>\n";
                        } while ($l = mysql_fetch_array($re));
                    }
                    ?>
                </table

            </div>

            <hr></hr>

            <div class="categoria">

                <?php
                echo "<form name=\"formvideo\" method=\"post\" action=\"recebevideo.php?pg=" . $pagina . "\" enctype=\"multipart/form-data\">"
                ?>
                <fieldset class="fields">
                    <legend><span class="spa">Inserir video:</span></legend>
                    <label>Descricao:</label>
                    <input name="descricao" type="text" id="descricao" maxlength="94" class="legenda" />	
                    <br></br>
                    <label>Link do Video:  </label>
                    <input name="linkvideo" type="text" id="linkvideo" maxlength="900" class="legenda" />	
                    <input type="button" value="Enviar" class="botao" onclick="validarcampos(formvideo)" />
                </fieldset>    

                <?php
                echo '</form>';
                ?>



                <br></br>

                <table width="100%" class="tab">
                    <tr>		
                        <td><label>LinkVideo</label></td>
                        <td><label>Descricao</label></td>
                        <td><label>Acoes</label></td>
                    </tr>
                    <?php
                    $re = mysql_query("SELECT  video.VideoId ,video.LinkVideo, video.Descricao
									FROM conteudo, nvideos, video
									WHERE conteudo.pagina =  '" . $pagina . "' AND 
									nvideos.idqualvideo = video.VideoId AND
									nvideos.idqualconteudo = conteudo.ConteudoId");
                    while ($l = mysql_fetch_array($re)) {
                        $link = $l["LinkVideo"];
                        $descvideo = $l["Descricao"];
                        $id = $l["VideoId"];
                        echo "<tr>						
							<td>&nbsp;$link</td>		
							<td>&nbsp;<label>$descvideo</label></td>
							<td><input type=\"button\" class=\"botao\" value=\"Excluir\" onclick=confirmarexcluirVideo($id,'$pagina');></td>		
						</tr>\n";
                    }
                    ?>
                </table>

            </div>
            <hr></hr>
        </div>



        <a href="Principal.php?pg=Principal"><span class="spa">Voltar</span></a>

    </body>
</html>
